package org.foj.model {

import mx.messaging.ChannelSet;
import mx.rpc.AsyncToken;
import mx.rpc.IResponder;
import mx.rpc.remoting.RemoteObject;
import mx.rpc.soap.WebService;

import org.foj.dto.Comment;

public class CommentModel {

  private var _commentService:RemoteObject;

  public function CommentModel() {
    var defaultChannelSet:ChannelSet = ChannelSetFactory.getDefaultChannel();

    _commentService = new RemoteObject();
    _commentService.destination = "commentService";
    _commentService.channelSet = defaultChannelSet;
  }

  public function getCommentsForIssueId(issueId:Number,
                                        responder:IResponder):void {
    var token:AsyncToken = _commentService.findCommentsByIssueId(issueId);
    token.addResponder(responder);
  }

  public function saveComment(comment:Comment,
                              responder:IResponder):void {
    var token:AsyncToken = _commentService.save(comment);
    token.addResponder(responder);
  }

  public function removeComment(id:Number,
                                responder:IResponder):void {
    var token:AsyncToken = _commentService.remove(id);
    token.addResponder(responder);
  }
}
}